/*******************************************************************************
 * Copyright (c) 2005, 2014 springside.github.io
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 *******************************************************************************/
package net.wofly.sale.order.repository;

import net.wofly.sale.order.domain.OrderType;
import net.wofly.sale.order.domain.RoleOrderType;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface RoleOrderTypeRepository
        extends PagingAndSortingRepository<RoleOrderType, String>, JpaSpecificationExecutor<RoleOrderType> {
    
    @Query("select ot from OrderType ot where ot.orderTypeID in (select rot.orderTypeID from RoleOrderType rot where " +
            "rot.roleID=:roleID) ")
    List<OrderType> findByRoleID(@Param("roleID") String roleID);
    
    @Query("select ot from OrderType ot where ot.orderTypeID in (select rot.orderTypeID from RoleOrderType rot where " +
            "rot.roleID=:roleID) and ot.status = :status ")
    List<OrderType> findByRoleIDAndStatus(@Param("roleID") String roleID, @Param("status") Integer status);
    
}